using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxSysChengXin class.
	/// </summary>
    [Serializable]
	public partial class CxSysChengXinCollection : ActiveList<CxSysChengXin, CxSysChengXinCollection>
	{	   
		public CxSysChengXinCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxSysChengXinCollection</returns>
		public CxSysChengXinCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxSysChengXin o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_SYS_ChengXin table.
	/// </summary>
	[Serializable]
	public partial class CxSysChengXin : ActiveRecord<CxSysChengXin>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxSysChengXin()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxSysChengXin(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxSysChengXin(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxSysChengXin(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_SYS_ChengXin", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarClassName = new TableSchema.TableColumn(schema);
				colvarClassName.ColumnName = "ClassName";
				colvarClassName.DataType = DbType.String;
				colvarClassName.MaxLength = 50;
				colvarClassName.AutoIncrement = false;
				colvarClassName.IsNullable = true;
				colvarClassName.IsPrimaryKey = false;
				colvarClassName.IsForeignKey = false;
				colvarClassName.IsReadOnly = false;
				colvarClassName.DefaultSetting = @"";
				colvarClassName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarClassName);
				
				TableSchema.TableColumn colvarTagName = new TableSchema.TableColumn(schema);
				colvarTagName.ColumnName = "tagName";
				colvarTagName.DataType = DbType.String;
				colvarTagName.MaxLength = 50;
				colvarTagName.AutoIncrement = false;
				colvarTagName.IsNullable = true;
				colvarTagName.IsPrimaryKey = false;
				colvarTagName.IsForeignKey = false;
				colvarTagName.IsReadOnly = false;
				colvarTagName.DefaultSetting = @"";
				colvarTagName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTagName);
				
				TableSchema.TableColumn colvarDetail = new TableSchema.TableColumn(schema);
				colvarDetail.ColumnName = "detail";
				colvarDetail.DataType = DbType.String;
				colvarDetail.MaxLength = 50;
				colvarDetail.AutoIncrement = false;
				colvarDetail.IsNullable = true;
				colvarDetail.IsPrimaryKey = false;
				colvarDetail.IsForeignKey = false;
				colvarDetail.IsReadOnly = false;
				colvarDetail.DefaultSetting = @"";
				colvarDetail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDetail);
				
				TableSchema.TableColumn colvarTypename = new TableSchema.TableColumn(schema);
				colvarTypename.ColumnName = "typename";
				colvarTypename.DataType = DbType.String;
				colvarTypename.MaxLength = 50;
				colvarTypename.AutoIncrement = false;
				colvarTypename.IsNullable = true;
				colvarTypename.IsPrimaryKey = false;
				colvarTypename.IsForeignKey = false;
				colvarTypename.IsReadOnly = false;
				colvarTypename.DefaultSetting = @"";
				colvarTypename.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTypename);
				
				TableSchema.TableColumn colvarShidu = new TableSchema.TableColumn(schema);
				colvarShidu.ColumnName = "shidu";
				colvarShidu.DataType = DbType.String;
				colvarShidu.MaxLength = 50;
				colvarShidu.AutoIncrement = false;
				colvarShidu.IsNullable = true;
				colvarShidu.IsPrimaryKey = false;
				colvarShidu.IsForeignKey = false;
				colvarShidu.IsReadOnly = false;
				colvarShidu.DefaultSetting = @"";
				colvarShidu.ForeignKeyTableName = "";
				schema.Columns.Add(colvarShidu);
				
				TableSchema.TableColumn colvarBaseScores = new TableSchema.TableColumn(schema);
				colvarBaseScores.ColumnName = "baseScores";
				colvarBaseScores.DataType = DbType.Int32;
				colvarBaseScores.MaxLength = 0;
				colvarBaseScores.AutoIncrement = false;
				colvarBaseScores.IsNullable = true;
				colvarBaseScores.IsPrimaryKey = false;
				colvarBaseScores.IsForeignKey = false;
				colvarBaseScores.IsReadOnly = false;
				colvarBaseScores.DefaultSetting = @"";
				colvarBaseScores.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBaseScores);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_SYS_ChengXin",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("ClassName")]
		[Bindable(true)]
		public string ClassName 
		{
			get { return GetColumnValue<string>(Columns.ClassName); }
			set { SetColumnValue(Columns.ClassName, value); }
		}
		  
		[XmlAttribute("TagName")]
		[Bindable(true)]
		public string TagName 
		{
			get { return GetColumnValue<string>(Columns.TagName); }
			set { SetColumnValue(Columns.TagName, value); }
		}
		  
		[XmlAttribute("Detail")]
		[Bindable(true)]
		public string Detail 
		{
			get { return GetColumnValue<string>(Columns.Detail); }
			set { SetColumnValue(Columns.Detail, value); }
		}
		  
		[XmlAttribute("Typename")]
		[Bindable(true)]
		public string Typename 
		{
			get { return GetColumnValue<string>(Columns.Typename); }
			set { SetColumnValue(Columns.Typename, value); }
		}
		  
		[XmlAttribute("Shidu")]
		[Bindable(true)]
		public string Shidu 
		{
			get { return GetColumnValue<string>(Columns.Shidu); }
			set { SetColumnValue(Columns.Shidu, value); }
		}
		  
		[XmlAttribute("BaseScores")]
		[Bindable(true)]
		public int? BaseScores 
		{
			get { return GetColumnValue<int?>(Columns.BaseScores); }
			set { SetColumnValue(Columns.BaseScores, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varClassName,string varTagName,string varDetail,string varTypename,string varShidu,int? varBaseScores)
		{
			CxSysChengXin item = new CxSysChengXin();
			
			item.ClassName = varClassName;
			
			item.TagName = varTagName;
			
			item.Detail = varDetail;
			
			item.Typename = varTypename;
			
			item.Shidu = varShidu;
			
			item.BaseScores = varBaseScores;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,string varClassName,string varTagName,string varDetail,string varTypename,string varShidu,int? varBaseScores)
		{
			CxSysChengXin item = new CxSysChengXin();
			
				item.Id = varId;
			
				item.ClassName = varClassName;
			
				item.TagName = varTagName;
			
				item.Detail = varDetail;
			
				item.Typename = varTypename;
			
				item.Shidu = varShidu;
			
				item.BaseScores = varBaseScores;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ClassNameColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TagNameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn DetailColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn TypenameColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn ShiduColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn BaseScoresColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string ClassName = @"ClassName";
			 public static string TagName = @"tagName";
			 public static string Detail = @"detail";
			 public static string Typename = @"typename";
			 public static string Shidu = @"shidu";
			 public static string BaseScores = @"baseScores";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
